<?php
/**
 * Created by PhpStorm.
 * User: Kau
 * Date: 2017/12/12
 * Time: 13:19
 */
namespace console\controllers;

use common\models\Comment;
use Yii;
use yii\console\Controller;

class SmsController extends Controller
{
    public function actionSend()
    {
        $newCommentCount = Comment::find()->where(['remind' => 0, 'status' => 1])->count();
        if ($newCommentCount > 0)
        {
            $content = 'You have '.$newCommentCount.' comment(s) to be reviewed.';
            $result = $this->verdorSmsService($content);
            if ($result['status'] == 'success')
            {
                //Comment::updateAll(['remind' => 1]);
                echo '['.date("Y-m-d H:i:s", $result['dt']).'] '.$content.'['.$result['length'].']';
            }
        }
        return 0;
    }

    protected function verdorSmsService($content)
    {
        $result = array("status" => "success", "dt" => time(), "length" => 43);
        return $result;
    }
}